package com.guodexian.mapper;
import com.guodexian.entity.Dish;
import org.apache.ibatis.annotations.*;

import java.util.List;
/**
 * 类说明：<br>
 *
 * @author qfrx<br>
 * 2024/12/26 18:48<br>
 * @since 1.0 <br>
 */
@Mapper
public interface DishMapper {
    @Results({
            @Result(property = "dishShop",column = "dish_shop_id",one =@One(select = "com.guodexian.mapper.ShopMapper.findById") )
    })
    @Select({
            "<script>",
            "  SELECT * FROM dish_star" ,
            "        <where>" ,
            "            <if test=\"shopId!=null and shopId!=-1\">" ,
            "                dish_shop_id = #{shopId}" ,
            "            </if>" ,
            "            <if test=\"dishName!=null and dishName!=''\">" ,
            "                and dish_name like concat('%',concat(#{dishName},'%'))",
            "            </if>" ,
            "        </where>",
            "order by dish_id desc",
            "</script>"
    })
    public List<Dish> selectBySearchVO(@Param("shopId") int shopId,@Param("dishName") String dishName);
    @Results({
            @Result(property = "dishShop",column = "dish_shop_id",one =@One(select = "com.guodexian.mapper.ShopMapper.findById") )
    })
    @Select({
            "  SELECT * FROM dish_star WHERE dish_shop_id = #{shopId} and dish_name = #{dishName}"
    })
    public Dish selectByNameAndShop(@Param("shopId") Integer shopId, @Param("dishName") String dishName);
    @Insert({"insert into  dish_star(dish_name, dish_img, dish_price, dish_month, dish_evaluate, dish_points, dish_detail, dish_shop_id)",
            "values (#{dishName},#{dishImg},#{dishPrice},#{dishMonth},#{dishEvaluate}, #{dishPoints}, #{dishDetail}, #{dishShopId})"})
    int insert(Dish dish);
    @Select({"  SELECT * FROM dish_star WHERE dish_id = #{id}"})
    Dish selectById(Integer id);
    @Update("update dish_star set dish_name=#{dishName}, dish_price=#{dishPrice}, dish_points=#{dishPoints}, dish_shop_id=#{dishShopId} where dish_id=#{dishId}")
    int update(Dish dish);
    @Delete("delete from dish_star where dish_id=#{id}")
    public int deleteById(Integer id);
    @Delete({
            "<script>",
            " delete from dish_star" ,
            "    where dish_id in " ,
            "    <foreach collection=\"array\" item=\"id\" open=\"(\" close=\")\" separator=\",\">" ,
            "        #{id}" ,
            "    </foreach>",
            "</script>"
    })
    public int  deleteByIds(Integer[] ids);
}
